package com.luguotao.lease.common.utils;

import java.util.List;
import java.util.Random;

public class CodeUtil {
    //自定义验证码的规则

    public static String originCode = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    public static String generateCode(int length){
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < length; i++) {
            //生成0-52的整数
            int index = new Random().nextInt(53);
            stringBuilder.append(originCode.charAt(index));
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        System.out.println(generateCode(6));
    }

    //不能发送其他，只能是数字
//    public static  String generateCode(int length){
//        StringBuilder stringBuilder=new StringBuilder();
//        for (int i = 0; i < length; i++) {
//            int code = new Random().nextInt(10);
//            stringBuilder.append(code);
//        }
//        return stringBuilder.toString();
//    }
}
